package com.ihr360.job.core.config;

import com.ihr360.job.core.repository.JobRepository;
import com.ihr360.job.core.step.StepBuilder;
import org.springframework.transaction.PlatformTransactionManager;

/**
 * Convenient factory for a {@link StepBuilder} which sets the {@link JobRepository} and
 * {@link PlatformTransactionManager} automatically.
 *
 * @author Dave Syer
 *
 */
public class StepBuilderFactory {
    private JobRepository jobRepository;

    private PlatformTransactionManager transactionManager;

    public StepBuilderFactory(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
        this.jobRepository = jobRepository;
        this.transactionManager = transactionManager;
    }

    /**
     * Creates a step builder and initializes its job repository and transaction manager. Note that if the builder is
     * used to create a &#64;Bean definition then the name of the step and the bean name might be different.
     *
     * @param name the name of the step
     * @return a step builder
     */
    public StepBuilder get(String name) {
        StepBuilder builder = new StepBuilder(name).repository(jobRepository).transactionManager(
                transactionManager);
        return builder;
    }
}